/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package logic;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;

/**
 *
 * @author do.ob
 */
public class PdfReader extends Reader{

    public PdfReader(File doc, Listener listener){
        super(doc, listener);
    }

    @Override
    public void run() {
        String textoPagina = "";
        Document docPDF = new Document();
        try {
            docPDF.setFile(doc.getPath());
        } catch (PDFException ex) {
            Logger.getLogger(PdfReader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (PDFSecurityException ex) {
            Logger.getLogger(PdfReader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(PdfReader.class.getName()).log(Level.SEVERE, null, ex);
        }
       for (int i = 0; i < docPDF.getNumberOfPages(); i++) {
           textoPagina = docPDF.getPageText(i).toString();
           listener.listo(textoPagina);
       }
       listener.fin();
    }

}
